package com.xiaoyu.shenyou.shenyouv1.utils;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.xiaoyu.shenyou.shenyouv1.common.shenyouentity.RootBean;
import com.xiaoyu.shenyou.shenyouv1.common.shenyouurl.ShenyouURL;

import java.util.HashMap;


public class ShenyouHttpClient {
    private ShenyouHttpClient() {
    }

    public static RootBean postNotToken(HashMap<String, Object> paramMap, String urlSuffix) {
        //调用接口，返回用户的数据
        HttpResponse gamesResp = HttpRequest.post(ShenyouURL.API_URL + urlSuffix)
                .body(JSONUtil.toJsonStr(paramMap))
                .timeout(10000)
                .execute();
        RootBean rootBean = JSONUtil.toBean(gamesResp.body(), RootBean.class);
        return rootBean;
    }

    public static RootBean post(HashMap<String, Object> paramMap, String urlSuffix, String token) {
        //调用接口，返回用户的数据
        HttpResponse gamesResp = HttpRequest.post(ShenyouURL.API_URL + urlSuffix)
                .header(Header.AUTHORIZATION, token)
                .body(JSONUtil.toJsonStr(paramMap))
                .timeout(10000)
                .execute();
        RootBean rootBean = JSONUtil.toBean(gamesResp.body(), RootBean.class);
        return rootBean;
    }

    public static RootBean post(Object paramMap, String urlSuffix) {
        //调用接口，返回用户的数据
        HttpResponse gamesResp = HttpRequest.post(ShenyouURL.API_URL + urlSuffix)
                .header(Header.AUTHORIZATION, ShenyouURL.TOKEN)
                .body(JSONUtil.toJsonStr(paramMap))
                .timeout(10000)
                .execute();
        RootBean rootBean = JSONUtil.toBean(gamesResp.body(), RootBean.class);
        return rootBean;
    }
}
